package com.hackerrank.challenges.pairs;

import java.util.Arrays;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), K = in.nextInt(), n[] = new int[N];
		for(int i = 0; i < N; i++)
			n[i] = in.nextInt();
		Arrays.sort(n);
		int l = 1, c = 0;
		for(int i = 0; i < N; i++) {
			l = Math.max(l, i + 1);
			int u = N - 1;
			while(l <= u) {
				int m = (l + u) / 2;
				if(n[m] > n[i] + K)
					u = m - 1;
				else if(n[m] < n[i] + K)
					l = m + 1;
				else if(n[m] == n[i] + K) {
					l = u = m;
					c++;
					break;
				}
			}
		}
		System.out.println(c);
	}
}
